package servlet;

import bean.Result;
import biz.PhoneBiz;
import com.google.gson.Gson;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "RemovePhoneServlet", value = "/RemovePhoneServlet.s")
public class RemovePhoneServlet extends HttpServlet {
    private PhoneBiz biz = new PhoneBiz();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Result result;
        String id = request.getParameter("id");
        String flag = request.getParameter("flag");
        try {
            if("逻辑删除".equals(flag)){
                biz.remove1(id);
            } else {
                biz.remove(id); //物理删除
            }
            result = new Result(1, "删除成功!", null);
        } catch (Exception e) {
            e.printStackTrace();
            result = new Result(0,"删除失败!", null );
        }
        String json = new Gson().toJson(result);
        response.getWriter().append(json);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
